package tree;

import offer.TreeNode;

public class leetCode108_sortedArrayToBST {
    public TreeNode sortedArrayToBST(int[] nums) {
        if(nums == null || nums.length == 0) return null;
        return build(nums,0,nums.length - 1);


    }

    public TreeNode build(int[] nums,int start,int end){
        if(start > end){
            return null;
        }

        int rootIndex = start + (end - start)/2;
        TreeNode treeNode = new TreeNode(nums[rootIndex]);
        treeNode.left = build(nums,start,rootIndex - 1);
        treeNode.right = build(nums,rootIndex + 1,end);
        return treeNode;
    }

}
